package com.tsky.system.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.tsky.casing.QueryBean;
import com.tsky.casing.action.BackAction;
import com.tsky.common.ActionUtil;
import com.tsky.common.BeanUtil;
import com.tsky.system.entity.Constant;
import com.tsky.system.json.JsonFormat;
import com.tsky.system.manager.ConstantManager;
import com.tsky.system.query.ConstantQuery;
@Component("constantAction")
@Scope("prototype")
public class ConstantAction extends BackAction {

	@Autowired
	private ConstantManager entityManager;

	/* bean properties */
	private String id;
	private String status;
	private String name;
	private String fieldName;
	private String fieldValue;
	private String showValue;//显示值
	private int orderNO;// 排序号

	private String ids;

	public void grid() {
		QueryBean grid = new ConstantQuery();
		BeanUtil.copyProperties(grid, this);

		entityManager.query(grid);

		String jsonData = JsonFormat.constantToJson(grid);
		ActionUtil.ajaxWrite(jsonData);
	}

	public void add() {
		Constant entity = new Constant();
		BeanUtil.copyProperties(entity, this);
		entity.setId(BeanUtil.getID());

		boolean result = entityManager.saveEntity(entity);
		ActionUtil.ajaxWrite(result);
	}

	public void delete() {
		String[] idset = ids.split(",");
		boolean result = entityManager.delEntity(Constant.class, idset);
		ActionUtil.ajaxWrite(result);
	}

	public String query() {
		Constant entity = entityManager.getEntity(Constant.class, id);
		ActionUtil.setToEL("constantEnt", entity);
		return "query";
	}

	public void update() {
		Constant entity = entityManager.getEntity(Constant.class, id);
		BeanUtil.copyProperties(entity, this);

		boolean result = entityManager.updateEntity(entity);
		ActionUtil.ajaxWrite(result);
	}

	/* spring DI */
	public ConstantManager getEntityManager() {
		return entityManager;
	}

	public void setEntityManager(ConstantManager entityManager) {
		this.entityManager = entityManager;
	}

	/* simple getter and setter */
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getFieldValue() {
		return fieldValue;
	}

	public void setFieldValue(String fieldValue) {
		this.fieldValue = fieldValue;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public String getShowValue() {
		return showValue;
	}

	public void setShowValue(String showValue) {
		this.showValue = showValue;
	}

	public int getOrderNO() {
		return orderNO;
	}

	public void setOrderNO(int orderNO) {
		this.orderNO = orderNO;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
